/*
' Copyright (c) 2011  Blue Age Software
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 
*/

using System;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;

namespace BAS.AutoLogin {

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The Settings class manages Module Settings
    /// </summary>
    /// -----------------------------------------------------------------------------
    public partial class Settings : ModuleSettingsBase {

        #region Base Method Implementations

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadSettings loads the settings from the Database and displays them
        /// </summary>
        /// -----------------------------------------------------------------------------
        public override void LoadSettings() {
            try {
                if (Page.IsPostBack == false) {
                    if (ModuleSettings["AutoLogin_UserName"] == null)
                        ModuleSettings["AutoLogin_UserName"] = "";
                    tbUserName.Text = ModuleSettings["AutoLogin_UserName"].ToString();

                    if (ModuleSettings["AutoLogin_Password"] == null)
                        ModuleSettings["AutoLogin_Password"] = "";
                    tbPassword.Text = ModuleSettings["AutoLogin_Password"].ToString();
                }
            } catch (Exception ex) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// UpdateSettings saves the modified settings to the Database
        /// </summary>
        /// -----------------------------------------------------------------------------
        public override void UpdateSettings() {
            try {
                ModuleController moduleController = new ModuleController();
                moduleController.UpdateModuleSetting(ModuleId, "AutoLogin_UserName", tbUserName.Text.Trim());
                moduleController.UpdateModuleSetting(ModuleId, "AutoLogin_Password", tbPassword.Text.Trim());
            } catch (Exception ex) {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        #endregion

    }

}

